package com.peas.platform.common.core.constant;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.net.NetUtil;
import cn.hutool.core.thread.ExecutorBuilder;
import cn.hutool.core.thread.ThreadFactoryBuilder;
import cn.hutool.core.util.RandomUtil;
import com.peas.platform.common.core.annotation.Aop;
import com.peas.platform.common.core.enums.BaseEnum;
import org.apache.poi.ss.usermodel.DataFormatter;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;

@Aop(enabled = false)
public class Constants {

    public static final long workerId = Math.abs(RandomUtil.randomInt()) % 32;

    public static final long dataCenterId = Math.abs(NetUtil.ipv4ToLong(NetUtil.getLocalhostStr())) % 32;

    public static final Snowflake snowflake = new Snowflake(workerId, dataCenterId);

    public static final int corePoolSize = 10;

    public static final int maxPoolSize = 20;

    public static final int workQueue = 20;

    public static final ExecutorService executor = ExecutorBuilder.create()
            .setCorePoolSize(corePoolSize)//初始线程
            .setMaxPoolSize(maxPoolSize)//最大线程
            .setWorkQueue(new LinkedBlockingQueue<>(workQueue))//有界等待队列，最大等待数
            .setThreadFactory(ThreadFactoryBuilder.create().setNamePrefix("IM-Pool-").build())//设置线程前缀
            .build();

    public static final DataFormatter df = new DataFormatter();

    public static final String BASE_PACKAGE = "com.peas.platform";

    public static final String CRITERIA_START = "Start";

    public static final String CRITERIA_END = "End";

    public static final String SUCCESS_CODE = "000";

    public static final String SUCCESS_MESSAGE = "操作成功";

    public static final String DEFAULT_ERROR_CODE = "999";

    public static final String DEFAULT_ERROR_MESSAGE = "操作失败";

    public static final String LOGIN_ERROR_CODE = "998";

    public static final String LOGIN_ERROR_MESSAGE = "登录超时";

    public static final String VALUE_PREFIX_ENUM = "枚举取值:";

    public static final String VALUE_PREFIX_DICT = "字典取值:";

    public static final String VALUE_PREFIX_FOREIGN = "外键表:";

    public static final Map<String, Class<? extends BaseEnum>> enums = new HashMap<>();

    /**
     * 当前记录起始索引
     */
    public static final String PAGE_NUM = "pageNum";

    public static final int DEFAULT_PAGE_NUM = 1;

    /**
     * 每页显示记录数
     */
    public static final String PAGE_SIZE = "pageSize";

    public static final int DEFAULT_PAGE_SIZE = 10;

    public static final String SORT_FIELD = "sortField";

    public static final String SORT_TYPE = "sortType";

    /**
     * 排序列
     */
    @Deprecated
    public static final String DEFAULT_SORT_FIELD = "id";

    public static final String FIELD_ID = "id";

    public static final String FIELD_DELETED = "deleted";

    public static final String FIELD_CREATEBY = "createBy";

    public static final String FIELD_CREATETIME = "createTime";

    public static final String FIELD_UPDATEBY = "updateBy";

    public static final String FIELD_UPDATETIME = "updateTime";

    public static final String FIELD_VERSION = "version";

    /**
     * 排序的方向 "desc" 或者 "asc".
     */
    public static final String SORT_ASC = "asc";

    public static final String SORT_DESC = "desc";

}
